﻿using BankSystem.Classes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BankSystem.Forms
{
    public partial class WithdrawForm : Form
    {
        ParentForm parentForm;
        public WithdrawForm(ParentForm form)
        {
            InitializeComponent();
            this.MdiParent = form;
            parentForm = form;
            WindowState = FormWindowState.Normal;
            MaximizeBox = false;
            Dock = DockStyle.Fill;
        }

        private void buttonConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                double amount = Double.Parse(textBoxAmount.Text);
                parentForm.withdrawMoney(amount, out string info);
                textBoxInfo.Text += info + "\r\n";
            }catch(ArgumentNullException)
            {
                textBoxInfo.Text += "输入错误" + "\r\n";
            }catch(FormatException)
            {
                textBoxInfo.Text += "输入错误" + "\r\n";
            }catch(AccountDealingException exp)
            {
                textBoxInfo.Text += exp.ToString() + "\r\n";
            }catch(BadCashException exp)
            {
                textBoxInfo.Text += exp.ToString() + "\r\n";
            }
        }

        private void buttonReturn_Click(object sender, EventArgs e)
        {
            textBoxAmount.Text = "";
            textBoxInfo.Text = "";
            parentForm.jumpToMainForm(this);
        }

        public void noticeBigMoney(double amount)
        {
            textBoxInfo.Text += "发现大额金额流动，涉及金额 " + amount + " 元，注意保护个人安全" + "\r\n";
        }
    }
}
